package com.learn.security.component;

import com.learn.security.bo.PermissionInfoBO;
import com.learn.security.cache.Cache;
import com.learn.security.constant.CacheName;
import com.learn.security.service.PermissionInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * @version 1.0
 * @author: YU.TAN
 * @date: 2023/6/27 23:55
 * @Description:
 */
@Component
public class InitProcessor {
    @Autowired
    private PermissionInfoService permissionService;
    @Autowired
    private Cache caffeineCache;

    @PostConstruct
    public void init() {
        List<PermissionInfoBO> permissionInfoList = permissionService.listPermissionInfoBO();
        permissionInfoList.forEach(permissionInfo -> {
            caffeineCache.put(CacheName.PERMISSION, permissionInfo.getPermissionUri() + ":" + permissionInfo.getPermissionMethod(), permissionInfo);
        });
    }
}
